<?php

namespace App\Service\Moment;

use App\Constants\ErrorCode;
use App\Model\Moment;
use App\Service\BaseService;

/**
 * 动态删除
 */
class MomentDelService extends BaseService
{
    public function handle()
    {
        $momentId = $this->request->input('moment_id', 0);
        if (!$momentId) return $this->setError(ErrorCode::PARAMETER_ERROR);
        $moment = Moment::find($momentId);
        $userId = $this->getUserId();
        if (!$userId || !$moment || $moment->user_id != $userId) {
            return $this->setError(ErrorCode::OP_NOT_VALID, '操作不合法，无法删除该动态！');
        }
        $ret = Moment::where('id', $momentId)->update(['status' => Moment::STATUS_DEL]);
        return ['result' => 1];
    }
}
